package cmd

import (
	"fmt"
	"pushgo/pkg"

	"github.com/spf13/cobra"
)

func init() {
	rootCmd.AddCommand(runCmd)
	// pushgo run -u admin
	runCmd.Flags().StringP("user", "u", "", "目标机器登录的用户")
	runCmd.Flags().StringP("mode", "m", "default", "运行模式[ 单命令模式 | 剧本模式 ]")
	runCmd.Flags().StringP("command", "c", "", "执行的命令")
	runCmd.Flags().StringP("destination", "d", "", "目标地址")
	runCmd.MarkFlagRequired("")
}

var runCmd = &cobra.Command{
	Use:   "run",
	Short: "执行任务",
	Run: func(cmd *cobra.Command, args []string) {
		user, _ := cmd.Flags().GetString("user")
		mode, _ := cmd.Flags().GetString("mode")
		command, _ := cmd.Flags().GetString("command")
		destination, _ := cmd.Flags().GetString("destination")

		// 调用内部业务逻辑
		fmt.Printf("执行任务：\nUSER: %s\n模式: %s\n执行命令: %s\n", user, mode, command)
		pkg.SSHRun(destination, command)
	},
}
